<div id="limitBoxDiv" class="ibox no-margins no-padding no-borders">
	<div class="ibox-title p-xs ljFixBoxTitle">
		<div class="btn btn-sm btn-success" id="selectAll"><i class="fa fa-paste">全选</i></div>
		<div class="btn btn-sm btn-default" id="clearAll"><i class="fa fa-paste">清空</i></div>
		<div class="btn btn-sm btn-primary pull-right" id="btnLimitSubmit"><i class="fa fa-paste">权限设置</i></div>
	</div>
	<div style="height:40px;"></div>
	<div class="ibox-content no-margins p-xs">
		<form method="post" action="/sys/user/limit" class="pageForm required-validate" onsubmit="return validateCallback(this, pageRefresh)">
			<input type="hidden" id="userId" name="userId" th:value="${sysUser.id}">
			<input type="hidden" id="limits" name="limits" value="">
			<input type="hidden" id="cmd5" name="cmd5" value="">
			<input type="hidden" id="uid" name="uid" value="">
			<input type="hidden" id="randomData" name="randomData" value="">
			<div class="tabs-container">
				<ul class="nav nav-tabs">
					<th:block th:each="model,vs:${sysModels}">
						<li th:class="${vs.count} == 1?'active':''"><a data-toggle="tab" th:href="@{'#model-'+${model.id}}"
																	   th:text="${model.modelName}"></a></li>
					</th:block>
				</ul>
				<div class="tab-content ">
					<th:block th:each="model,vs:${sysModels}">
						<div th:if="${vs.count == 1}" th:id="@{'model-'+${model.id}}" class="tab-pane active" layoutH="232">
							<div class="panel-body">
								<table class="table table-striped">
									<tbody>
									<div th:unless="${#lists.isEmpty(modelResource[model.id])}"
										 th:include="sys/user/child"
										 th:with="index=0,level=0,treeList=${modelResource[model.id]}"></div>
									</tbody>
								</table>
							</div>
						</div>
						<div th:if="${vs.count > 1}" th:id="@{'model-'+${model.id}}" class="tab-pane">
							<div class="panel-body">
								<table class="table table-striped">
									<tbody>
									<div th:unless="${#lists.isEmpty(modelResource[model.id])}"
										 th:include="sys/user/child :: userChild"
										 th:with="index=0,level=0,treeList=${modelResource[model.id]}"></div>
									</tbody>
								</table>
							</div>
						</div>
					</th:block>
				</div>
			</div>
		</form>
	</div>
</div>
<script>
	jQuery(function ($) {
		$("[layoutH]").layoutH();
		$('.i-checks').iCheck({
			checkboxClass: 'icheckbox_square-green',
			radioClass: 'iradio_square-green',
		});
		$("#selectAll").on("click", function () {
			$('input[type="checkbox"]').iCheck('check');
		});
		$("#clearAll").on("click", function () {
			$('input[type="checkbox"]').iCheck('uncheck');
		});
		$("#btnLimitSubmit").on("click", function () {
			var limits = "";
			$('input[type="checkbox"]').each(function () {
				if ($(this).is(':checked')) {
					limits = limits + "," + $(this).val();
				}
			});
			var title = "确认提交该用户权限变更么?"
			if (limits === '') {
				title = "确认清除该用户权限么?";
			}
			swal({
				title: title,
				type: "warning",
				showCancelButton: true,
				confirmButtonColor: "#DD6B55",
				confirmButtonText: "提交",
				cancelButtonText: "取消",
				closeOnConfirm: false
			}, function () {
				$("#limits").val(limits);
				$("#limitBoxDiv form").submit();
			});
		});
	});
</script>